From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sat, 10 Aug 2024 20:23:50 +0000 (-0600) Subject: have jeeps use std::endian (#1315) X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2^2~73 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22Program/%22http:/www.example.com/cgi/%22https:/%22Program?a=commitdiff_plain;h=cfd661ded29e4ff264da5a7e0813c65faa402c35;p=gpsbabel.git have jeeps use std::endian (#1315) * have jeeps use std::endian * detect unsupported endian platforms. --- diff --git a/jeeps/gpsapp.cc b/jeeps/gpsapp.cc index d56a603e1..e810c9f3c 100644 --- a/jeeps/gpsapp.cc +++ b/jeeps/gpsapp.cc @@ -168,8 +168,6 @@ int32_t GPS_Init(const char* port) { int32_t ret; - (void) GPS_Util_Little(); - ret = GPS_A000(port); if (ret<0) { return ret; diff --git a/jeeps/gpscom.cc b/jeeps/gpscom.cc index afa1239f5..dcc56634d 100644 --- a/jeeps/gpscom.cc +++ b/jeeps/gpscom.cc @@ -44,8 +44,6 @@ int32_t GPS_Command_Off(const char* port) GPS_Packet tra; GPS_Packet rec; - GPS_Util_Little(); - if (!GPS_Device_On(port, &fd)) { return gps_errno; } diff --git a/jeeps/gpsutil.cc b/jeeps/gpsutil.cc index 9da4a9b1d..d88d3e57f 100644 --- a/jeeps/gpsutil.cc +++ b/jeeps/gpsutil.cc @@ -22,11 +22,14 @@ ** Boston, MA 02110-1301, USA. ********************************************************************/ #include "jeeps/gps.h" +#include #include #include -static int32_t gps_endian_called = 0; -static int32_t GPS_Little = 0; +static_assert((std::endian::native == std::endian::little) != + (std::endian::native == std::endian::big), + "Only big or little endian platforms are supported."); +static constexpr bool GPS_Little = std::endian::native == std::endian::little; int32_t gps_warning = 0; int32_t gps_error = 0; @@ -34,35 +37,6 @@ int32_t gps_user = 0; int32_t gps_show_bytes = 0; int32_t gps_errno = 0; -/* @func GPS_Util_Little *********************************************** -** -** Determine endian nature of host -** -** @return [int32] true if little-endian -************************************************************************/ - -int32_t GPS_Util_Little() -{ - static union lb { - char chars[sizeof(int32_t)]; - int32_t i; - } - data; - - if (!gps_endian_called) { - gps_endian_called = 1; - data.i = 0; - *data.chars = '\1'; - if (data.i == 1) { - GPS_Little = 1; - } else { - GPS_Little = 0; - } - } - - return GPS_Little; -} - /* @func GPS_Util_Get_Short ******************************************** ** @@ -78,7 +52,7 @@ US GPS_Util_Get_Short(const UC* s) p = (UC*)&ret; - if (!GPS_Little) { + if constexpr(!GPS_Little) { *p++ = *(s+1); *p = *s; } else { @@ -105,7 +79,7 @@ void GPS_Util_Put_Short(UC* s, const US v) { const auto* p = reinterpret_cast(&v); - if (!GPS_Little) { + if constexpr(!GPS_Little) { *s++ = *(p+1); *s = *p; } else { @@ -134,7 +108,7 @@ double GPS_Util_Get_Double(const UC* s) p = (UC*)&ret; - if (!GPS_Little) + if constexpr(!GPS_Little) for (i=sizeof(double)-1; i>-1; --i) { *p++ = s[i]; } @@ -164,7 +138,7 @@ void GPS_Util_Put_Double(UC* s, const double v) const auto* p = reinterpret_cast(&v); - if (!GPS_Little) + if constexpr(!GPS_Little) for (i=sizeof(double)-1; i>-1; --i) { s[i] = *p++; } @@ -195,7 +169,7 @@ int32_t GPS_Util_Get_Int(const UC* s) p = (UC*)&ret; - if (!GPS_Little) + if constexpr(!GPS_Little) for (i=sizeof(int32_t)-1; i>-1; --i) { *p++ = s[i]; } @@ -225,7 +199,7 @@ void GPS_Util_Put_Int(UC* s, const int32_t v) const auto* p = reinterpret_cast(&v); - if (!GPS_Little) + if constexpr(!GPS_Little) for (i=sizeof(int32_t)-1; i>-1; --i) { s[i] = *p++; } @@ -255,7 +229,7 @@ uint32_t GPS_Util_Get_Uint(const UC* s) p = (UC*)&ret; - if (!GPS_Little) + if constexpr(!GPS_Little) for (i=sizeof(uint32_t)-1; i>-1; --i) { *p++ = s[i]; } @@ -285,7 +259,7 @@ void GPS_Util_Put_Uint(UC* s, const uint32_t v) const auto* p = reinterpret_cast(&v); - if (!GPS_Little) + if constexpr(!GPS_Little) for (i=sizeof(uint32_t)-1; i>-1; --i) { s[i] = *p++; } @@ -315,7 +289,7 @@ float GPS_Util_Get_Float(const UC* s) p = (UC*)&ret; - if (!GPS_Little) + if constexpr(!GPS_Little) for (i=sizeof(float)-1; i>-1; --i) { *p++ = s[i]; } @@ -345,7 +319,7 @@ void GPS_Util_Put_Float(UC* s, const float v) const auto* p = reinterpret_cast(&v); - if (!GPS_Little) + if constexpr(!GPS_Little) for (i=sizeof(float)-1; i>-1; --i) { s[i] = *p++; } diff --git a/jeeps/gpsutil.h b/jeeps/gpsutil.h index 0e50f703a..5560eda29 100644 --- a/jeeps/gpsutil.h +++ b/jeeps/gpsutil.h @@ -4,8 +4,6 @@ #include "jeeps/gps.h" -int32_t GPS_Util_Little(); - US GPS_Util_Get_Short(const UC* s); void GPS_Util_Put_Short(UC* s, US v); int32_t GPS_Util_Get_Int(const UC* s);